package com.example.demo.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.auth0.jwt.JWT;

import com.example.demo.GeneralResponse.APIResponse;
import com.example.demo.Service.HRService;

/**
 * @version: V0.3
 * @author: 郑皓杰 吴嘉鑫
 * @className: UploadController
 * @packageName: com.example.demo.Controller
 * @description: 这是进行文件上传的控制类
 * @data: 2021-07-16
 **/

@Controller
@RequestMapping("/upload")
public class UploadController {
	@Autowired
	private HRService hrService;
	
	@ResponseBody
	@RequestMapping("/hrupload")
	public APIResponse<?> upLoad(HttpServletRequest Request,HttpServletResponse Response,MultipartFile file)throws Throwable{
		return APIResponse.success(hrService.upload(file,JWT.decode(Request.getHeader("Token")).getClaim("username").asString()),null);
	}
	
	
	@ResponseBody
	@RequestMapping("/hrdownload")
	public APIResponse<?> downLoad(HttpServletRequest Request,HttpServletResponse Response,MultipartFile file)throws Throwable{
		return hrService.download(JWT.decode(Request.getHeader("Token")).getClaim("username").asString(),Response);
	}
	
	

}
